home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / B_FRPROC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  25KB  |  792 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                   BinkleyTerm File Request Processor                     */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n343.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  43. /*  The original work is (C) Copyright 1987, Wynn Wagner III. The original  */
  44. /*  author has graciously allowed us to use his code in this work.          */
  45. /*                                                                          */
  46. /*--------------------------------------------------------------------------*/
  47.  
  48. /* Include this file before any other includes or defines! */
  49.  
  50. #include "includes.h"
  51.  
  52. static char *their_pwd;                         /* Password in REQ file */
  53. static char required_pwd[10];                   /* Password in OK file  */
  54. static int xfer_seconds;
  55.  
  56. int prep_match (char *, char *);
  57. int match (char *, char *);
  58. void run_prog (char *);
  59. int check_password (void);
  60. freq_abort (long, int (*)(long));
  61. int what_event (int);
  62. int what_event_sub (int, int, int, int, int, int);
  63.  
  64. int prep_match (char *template, char *buffer)
  65. {
  66.    register int i, delim;
  67.    register char *sptr;
  68.    int start;
  69.  
  70.    (void) memset (buffer, 0, 11);
  71.  
  72.    i = (int) strlen (template);
  73.    sptr = template;
  74.  
  75.  
  76.    for (start = i = 0; sptr[i]; i++)
  77.       if ((sptr[i] == '\\') || (sptr[i] == ':'))
  78.          start = i + 1;
  79.  
  80.    if (start)
  81.       sptr += start;
  82.    delim = 8;                                    /* last column for ? */
  83.  
  84.    (void) strupr (sptr);
  85.  
  86.    for (i = 0; *sptr && i < 12; sptr++)
  87.       switch (*sptr)
  88.          {
  89.          case '.':
  90.             if (i > 8)
  91.                return (-1);
  92.             while (i < 8)
  93.                {
  94.                buffer[i++] = ' ';
  95.                }
  96.             buffer[i++] = *sptr;
  97.             delim = 12;
  98.             break;
  99.  
  100.          case '*':
  101.             while (i < delim)
  102.                {
  103.                buffer[i++] = '?';
  104.                }
  105.             break;
  106.  
  107.          default:
  108.             buffer[i++] = *sptr;
  109.             break;
  110.  
  111.          }                                       /* switch */
  112.  
  113.    while (i < 12)
  114.       {
  115.  
  116. /* dean suggests:
  117.  
  118.       buffer[i++] = (i == delim) ? '.' : ((i > delim) ? '?' : ' ');
  119.  
  120.    to replace the if/else below... 
  121. */
  122.       if (i == 8)
  123.          buffer[i++] = '.';
  124.       else buffer[i++] = ' ';
  125.       }
  126.  
  127.    buffer[i] = '\0';
  128.  
  129.    return 0;
  130. }
  131.  
  132. int match (char *s1, char *s2)
  133. {
  134.    register char *i, *j;
  135.  
  136.    i = s1;
  137.    j = s2;
  138.  
  139.    while (*i)
  140.       {
  141.       if ((*j != '?') && (*i != *j))
  142.          {
  143.          return 1;
  144.          }
  145.       i++;
  146.       j++;
  147.       }
  148.  
  149.    return 0;
  150. }
  151.  
  152. /*--------------------------------------------------------------------------*/
  153. /* Process file requests from the remote system. The filespec requested is  */
  154. /* turned into a local filespec if possible, then transferred via the       */
  155. /* caller-supplied routine.                                                 */
  156. /*--------------------------------------------------------------------------*/
  157.  
  158. int n_frproc (char *request, int nfiles,
  159.               int (*callback)(char *), int (*calltime)(long))
  160. {
  161.    register int i;
  162.    register int j = 0;
  163.    static char s[80];
  164.    static char s1[80];
  165.    static char s2[80];
  166.    char *p;
  167.  
  168.    FILE *approved;
  169.    struct FILEINFO dta;
  170.    struct stat st;
  171.    char *sptr;
  172.  
  173.    char *after_pwd;
  174.    long updreq = 0L;
  175.    char updtype = 0;
  176.    int saved_nfiles;
  177.  
  178.    char our_wildcard[15];
  179.    char their_wildcard[15];
  180.    int mfunc;
  181.    int magic_state = 0;
  182.    int tried_about = 0;
  183.  
  184.    int failure_reason = 1;                      /* 1 = not available */
  185.                                                 /* 2 = no update     */
  186.                                                 /* 3 = bad password  */
  187.    if (freq_accum.time == 0L)
  188.       freq_accum.time = (long)time(NULL);
  189.  
  190.    approved = NULL;
  191.    their_pwd = NULL;
  192.    after_pwd = NULL;
  193.    (void) strcpy (s1, request);
  194.  
  195.    /*--------------------------------------------------------------------*/
  196.    /* Fix up the file name                                               */
  197.    /*--------------------------------------------------------------------*/
  198.    for (i = 0; request[i]; i++)
  199.       {
  200.       if (request[i] <= ' ')
  201.          {
  202.          request[i++] = '\0';
  203.          j = i;
  204.          break;
  205.          }
  206.       }
  207.    
  208.    if (j)
  209.       {
  210.       /* If we have a '!', find the end of the password, point j
  211.          past it, then truncate and fold if necessary. This leaves
  212.          j properly aligned for other fields.
  213.        */
  214.  
  215.       if (request[j] == '!')
  216.          {
  217.          their_pwd = request + (++j);
  218.          for (; request[j]; j++)
  219.             {
  220.             if (request[j] <= ' ')
  221.                {
  222.                request[j++] = '\0';
  223.                break;
  224.                }
  225.             }
  226.  
  227.          if (strlen (their_pwd) > 6)
  228.             their_pwd[6] = '\0';
  229.  
  230.          (void) fancy_str (their_pwd);
  231.          }
  232.  
  233.       /* Test for update/back